package com.avapir.snake.Core.Listeners;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

import com.avapir.snake.Actors.NPC.Food;
import com.avapir.snake.Actors.NPC.Food.FoodType;
import com.avapir.snake.Core.Core;
import com.avapir.snake.Core.Painter;
import com.avapir.snake.UI.Game;

/**
 * It's cheating class added to make debugging easier. Removing on release is optional ;)
 * @author Alpen Ditrix
 */
@SuppressWarnings("deprecation")
public class AdminListener implements KeyListener {

	private static void growFood(FoodType f) {
		final Random r = new Random();
		int rr = r.nextInt(Painter.getWidth());
		int x = rr - rr % Painter.getCellSize();
		rr = r.nextInt(Painter.getHeight() - 30) + 30;
		int y = rr - rr % Painter.getCellSize();
		new Food(f, x, y);
	}

	@Override
	public void keyPressed(KeyEvent e) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_1:
			growFood(FoodType.VALHALLA);
			break;
		case KeyEvent.VK_0:
			Game.gameOver(Game.getSnakes().get(Game.getMySnake_ID()));
			break;
		case KeyEvent.VK_2:
			growFood(FoodType.TYPICAL);
			break;
		case KeyEvent.VK_3:
			growFood(FoodType.BIG);
			break;
		case KeyEvent.VK_4:
			growFood(FoodType.INVULNERABILITY);
			break;
		case KeyEvent.VK_5:
			growFood(FoodType.WALL);
			break;
		case KeyEvent.VK_D:
			Game.getSnakes().get(0).addAdminDonut();
			break;
		case KeyEvent.VK_G:
			// Game.getSnakes().get(0).addAdminGodPower();
			break;
		case KeyEvent.VK_F1:
			if (Core.getState() == Core.ScreenState.PLAYING)
				Core.invokePause();
			else if (Core.getState() == Core.ScreenState.PAUSE_MENU)
				Core.invokeReturnToGame();
			break;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub

	}

}
